package com.songtech.utils;

import com.songtech.server.constant.Calculate;

/**
 * Created with IntelliJ IDEA.
 * Description: 转换工具类
 *
 * @Author: rentie
 * @Date: 2018/4/13 10:52
 **/
public class ChangeUtil {

    public static double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
    public static double a = 6378245.0;

    /**
     * Long类型经纬度值转换为Double  1135833462=====>113.5833462
     * @param number
     * @return
     */
    public static Double LongToDouble(Long number) {

        return new Double(number/ Calculate.LON_LAT_FACTOR+"."+number % Calculate.LON_LAT_FACTOR);

    }


    /**
     * lon 经度
     * lat 纬度
     * GCJ-02转换BD-09
     * 谷歌地图经纬度转百度地图经纬度
     * */
    public static double[] gcj02ToBd09(double lon, double  lat) {
        double y  = lon, x = lat;
        double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
        double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
        double tempLat = z * Math.cos(theta) + 0.0032;
        double tempLon = z * Math.sin(theta) + 0.01;
        double[] gps = {tempLon,tempLat};
        return gps;
    }

    /**保留小数点后六位
     * @param num
     * @return
     */
    private static double retain6(double num){
        String result = String .format("%.6f", num);
        return Double.valueOf(result);
    }
}
